export class ManageQuery {

  constructor(manageLayer) {
    this._manageLayer = manageLayer;
  }

  //TODO 有待研究
  queryAttribute(uniqueId, where = "1=1", outFields = "*") {
    let type = this._manageLayer.getLayerTypeByUniqueId(uniqueId);
    if (!(type == "FeatureLayer" || type == "Sublayer" || type == "SceneLayer" || type == "CSVLayer" || type == "GeoJSONLayer")) {
      console.error("该方法只支持这些类型:FeatureLayer,Sublayer,SceneLayer,CSVLayer,GeoJSONLayer")
      return;
    }
    let layer = this._manageLayer.getLayerByUniqueId(uniqueId);
    var query = layer.createQuery();
    query.where = where;
    query.outFields = outFields;
    return layer.queryFeatures(query)
  }

  querySpatial(uniqueId,where,outFields) {
    let type = this._manageLayer.getLayerTypeByUniqueId(uniqueId);
    if (!(type == "FeatureLayer" || type == "Sublayer" || type == "SceneLayer" || type == "CSVLayer" || type == "GeoJSONLayer")) {
      console.error("该方法只支持这些类型:FeatureLayer,Sublayer,SceneLayer,CSVLayer,GeoJSONLayer")
      return;
    }
    let layer = this._manageLayer.getLayerByUniqueId(uniqueId);
    var query = layer.createQuery();
    query.geometry = view.toMap(event);  // the point location of the pointer
    query.spatialRelationship = "intersects";  // this is the default
    query.returnGeometry = true;
    query.outFields = outFields;

    featureLayerView.queryFeatures(query)
      .then(function(response){
        // returns a feature set with features containing the
        // POPULATION attribute and each feature's geometry
      });
  }

  querystatistic() {
  }

}
